package com.springmvc.web.servlet.mvc.method;


import java.util.Objects;

/**
 * 请求映射信息
 */
public class RequestMappingInfo {
    private String requestURI;

    private String method;

    public String getRequestURI() {
        return requestURI;
    }

    public void setRequestURI(String requestURI) {
        this.requestURI = requestURI;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public RequestMappingInfo() {
    }

    public RequestMappingInfo(String requestURI, String method) {
        this.requestURI = requestURI;
        this.method = method;
    }


    /**
     * 这里 hashcode equals必须重写
     * RequestMappingInfo a = new RequestMappingInfo("/a","get");
     * RequestMappingInfo a = new RequestMappingInfo("/a","get");
     * 不重写的话这两个对象是相等的，但是他们的hashcode是不一样的
     * 那么RequestMappingHandlerMapping中的map中每次就是不同的值，所以无法匹配
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RequestMappingInfo that = (RequestMappingInfo) o;
        return Objects.equals(requestURI, that.requestURI) && Objects.equals(method, that.method);
    }

    @Override
    public int hashCode() {
        return Objects.hash(requestURI, method);
    }
}
